<template>
  <el-container class="layout-container">
    <el-aside :width="isCollapse ? '64px' : '200px'" class="aside">
      <div class="logo">
        <span v-show="!isCollapse">养老院管理系统</span>
        <span v-show="isCollapse">系统</span>
      </div>
      <el-menu
        :default-active="activeMenu"
        class="menu"
        :collapse="isCollapse"
        router
        unique-opened
      >
        <el-menu-item index="/">
          <el-icon><User /></el-icon>
          <template #title>咨询列表</template>
        </el-menu-item>
        <el-menu-item index="/consult/add">
          <el-icon><Plus /></el-icon>
          <template #title>新增咨询</template>
        </el-menu-item>
        <el-sub-menu index="2">
          <template #title>
            <el-icon><House /></el-icon>
            <span>入住管理</span>
          </template>
          <el-menu-item index="/resident">入住列表</el-menu-item>
          <el-menu-item index="/resident/add">新增入住</el-menu-item>
        </el-sub-menu>
        <el-sub-menu index="3">
          <template #title>
            <el-icon><Setting /></el-icon>
            <span>系统设置</span>
          </template>
          <el-menu-item index="/settings/user">用户管理</el-menu-item>
          <el-menu-item index="/settings/role">角色管理</el-menu-item>
        </el-sub-menu>
      </el-menu>
    </el-aside>
    <el-container class="main-container">
      <el-header class="header">
        <div class="header-left">
          <el-icon class="toggle-icon" @click="toggleCollapse">
            <Fold v-if="!isCollapse" />
            <Expand v-else />
          </el-icon>
        </div>
        <div class="header-right">
          <el-dropdown>
            <span class="user-info">
              管理员
              <el-icon><CaretBottom /></el-icon>
            </span>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item>个人信息</el-dropdown-item>
                <el-dropdown-item>修改密码</el-dropdown-item>
                <el-dropdown-item divided>退出登录</el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
        </div>
      </el-header>
      <el-main class="main">
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script setup lang="ts">
import { ref, computed } from 'vue'
import { useRoute } from 'vue-router'
import { User, House, Setting, Expand, Fold, Plus, CaretBottom } from '@element-plus/icons-vue'

defineOptions({
  name: 'MainLayout',
})

const route = useRoute()
const isCollapse = ref(false)

const activeMenu = computed(() => route.path)

const toggleCollapse = () => {
  isCollapse.value = !isCollapse.value
}
</script>

<style scoped>
.layout-container {
  height: 100vh;
  width: 100vw;
  position: fixed;
  top: 0;
  left: 0;
}

.aside {
  background-color: #304156;
  color: #fff;
  overflow: hidden;
  transition: width 0.3s;
  height: 100%;
}

.logo {
  height: 50px;
  line-height: 50px;
  text-align: center;
  font-size: 16px;
  font-weight: bold;
  color: #fff;
  background-color: #2b3649;
  overflow: hidden;
  white-space: nowrap;
}

.menu {
  border-right: none;
  background-color: #304156;
  height: calc(100% - 50px);
}

:deep(.el-menu) {
  border-right: none;
}

:deep(.el-menu--vertical) {
  background-color: #304156;
}

:deep(.el-sub-menu__title) {
  color: #bfcbd9 !important;
}

:deep(.el-menu-item) {
  color: #bfcbd9 !important;
}

:deep(.el-menu-item.is-active) {
  color: #409eff !important;
  background-color: #263445 !important;
}

:deep(.el-sub-menu__title:hover),
:deep(.el-menu-item:hover) {
  background-color: #263445 !important;
}

:deep(.el-menu-item .el-icon),
:deep(.el-sub-menu__title .el-icon) {
  color: #bfcbd9;
}

:deep(.el-menu-item.is-active .el-icon) {
  color: #409eff;
}

.main-container {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.header {
  height: 50px;
  background-color: #fff;
  border-bottom: 1px solid #e6e6e6;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 15px;
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
}

.toggle-icon {
  font-size: 20px;
  cursor: pointer;
  color: #606266;
}

.header-right {
  display: flex;
  align-items: center;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  color: #606266;
}

.main {
  flex: 1;
  padding: 15px;
  background-color: #f0f2f5;
  overflow: auto;
  box-sizing: border-box;
  min-width: 1000px;
}

:deep(.el-menu--collapse) {
  width: 64px;
}

:deep(.el-menu-item),
:deep(.el-sub-menu__title) {
  height: 50px;
  line-height: 50px;
}
</style>
